package com.dnb.webmash.playmaker.shared;

import javax.jdo.annotations.EmbeddedOnly;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;

import com.google.gwt.user.client.rpc.IsSerializable;

@PersistenceCapable
@EmbeddedOnly
public class MyURL implements IsSerializable, Comparable<MyURL> {
	@Persistent
	private String myValue;
	
	public MyURL(){		
	}
	
	public MyURL(String url){//TODO VERIFY IS VALID AND THROW
		myValue = url;
	}
	@Override
	public String toString(){
		return myValue;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((myValue == null) ? 0 : myValue.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		MyURL other = (MyURL) obj;
		if (myValue == null) {
			if (other.myValue != null)
				return false;
		} else if (!myValue.equals(other.myValue))
			return false;
		return true;
	}
	
	@Override
	public int compareTo(MyURL obj){
		if (this.equals(obj))
			return 0;		
		else if (obj.myValue.toLowerCase().contains(myValue.toLowerCase()))
			return -1;
		else //if (myValue.toLowerCase().contains(obj.myValue.toLowerCase()))
			return 1; //default to this if they are not equal and this object is not contained in the arg obj.
	}
}
